package com.woniu.aimd.controller;

import cn.dev33.satoken.util.SaResult;
import com.woniu.aimd.pojo.entity.StudentFavorites;
import com.woniu.aimd.service.StudentFavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zcnovice
 * @data 2025/6/10 下午4:51
 */
@RequestMapping("/studentFavorites")
@RestController
public class StudentFavoritesController {
    @Autowired
    private StudentFavoritesService studentFavoritesService;


    /**
     * @Description: 添加到收藏夹--测试通过
     * @return:
     * @Author:  zcnovice
     * @date:  2025/6/10 下午4:54
     */
    @PostMapping("/insert")
    public SaResult insert(@RequestBody StudentFavorites studentFavorites){
        boolean result = studentFavoritesService.insert(studentFavorites);
        if(!result){
            return SaResult.error("添加失败");
        }
        return SaResult.ok("添加成功");
    }

    /**
     * @Description: 重收藏夹里面删除--测试通过
     * @return:
     * @Author:  zcnovice
     * @date:  2025/6/10 下午4:55
     */
    @DeleteMapping("/delete")
    public SaResult delete(String id){
        boolean result = studentFavoritesService.delete(id);
        if(!result){
            return SaResult.error("删除失败");
        }
        return SaResult.ok("删除成功");
    }


    /**
     * @Description: 查看收藏夹(查询的是id)
     * @return:
     * @Author:  zcnovice
     * @date:  2025/6/10 下午5:00
     */
    @GetMapping("/findByUser")
    public SaResult findByUser(StudentFavorites studentFavorites){
        List<Integer> result = studentFavoritesService.findByFavorites(studentFavorites);
        if(result.isEmpty()){
            return SaResult.error("没有数据");
        }
        return SaResult.ok("查询成功").set("data",result);
    }


}
